package com.zxbg.dao;

import com.zxbg.domain.ProcessRule;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProcessRuleDao {
    @Select("select * from process_rule where process_rule_code = #{code}")
    public ProcessRule getProcessRuleByCode(@Param("code") String code, @Param("tenant_id") Integer tenant_id);

    @Insert("insert into process_rule values (#{process_rule_code}, #{process_rule_name}, 0, #{describe}, #{tenant_id}, #{creator_id}, NOW(), NOW(), #{updater_id})")
    public int addRule(ProcessRule processRule);

    @Select("select * from process_rule where (process_rule_code like #{key} or process_rule_name like #{key} and tenant_id = #{tenant_id})")
    public List<ProcessRule> getAllProcessRule(@Param("key") String key, @Param("tenant_id") Integer tenant_id);

    @Select("select * from process_rule where (process_rule_code like #{key} or process_rule_name like #{key} and tenant_id = #{tenant_id} and creator_id = #{creator_id})")
    public List<ProcessRule> getAllProcessRuleByCreator(@Param("key") String key, @Param("tenant_id") Integer tenant_id, @Param("creator_id") String creator_id);

    @Update("update process_rule set process_rule_name = #{process_rule_name}, `describe` = #{describe}, update_time = NOW(), updater_id = #{updater_id} where process_rule_code = #{process_rule_code} and tenant_id = #{tenant_id}")
    public int updateProcessRule(ProcessRule processRule);

    @Delete("delete from process_rule where process_rule_code = #{process_rule_code} and tenant_id = #{tenant_id}")
    public int deleteProcessRule(@Param("process_rule_code") String process_rule_code, @Param("tenant_id") Integer tenant_id);

    @Update("update process_rule set `status` = 1 where process_rule_code = #{process_rule_code} and tenant_id = #{tenant_id}")
    public int setStatusBy(@Param("process_rule_code") String process_rule_code, @Param("tenant_id") Integer tenant_id);

    @Update("update process_rule set update_time = NOW(), updater_id = #{updater_id} where process_rule_code = #{process_rule_code}")
    public int updateUpdater(@Param("process_rule_code") String process_rule_code, @Param("updater_id") String updater_id, @Param("tenant_id") Integer tenant_id);
}
